	var m1 = new MyModal.modal(function() {
		});
$(function(){
	$(".grsz-phone").text($("#userId").attr("username"))
	if($("#userId").attr("idnum")!==""){
		$(".szName").attr("readonly","readonly");
		$(".szSfz").attr("readonly","readonly");
		$(".szName").val($("#userId").attr("readlname"))
		$(".szSfz").val($("#userId").attr("idNum"))
		$(".szEmail").val($("#userId").attr("email"))
		// $(".szBri").attr("readonly","readonly");
	}
	$(".szSfz").blur(function(){
		checkSFZ($(this).val());
	})
	$(".m-btn-shouye").click(function(){
		m1.hide();
	})
    $(".m-btn-sure").click(function(){

    		$.ajax({
    			url : "front/user/setUserInfo.do",
    			type : "POST",
    			data : {
    				"realName":$(".szName").val(),
    				"idNum":$(".szSfz").val(),
    				"birthday" : $(".szBri").val(),
    				"email":$(".szEmail").val()
    			},
    			dataType : "JSON",
    			success : function(json) {
    				if (json.code == 0) {
    					window.location.reload();
    				}else{
    					alert(json.message);
    				}
    				}
    			});
    	
    })
	
	
	$(".xgBtn").click(function(){
		if(checkSFZ($(".szSfz").val())){
			if($(".szName").val()!==""){
				$(".szName").parent().find(".tishishufu").css("display","none");
				m1.show();
			}else{
				$(".szName").parent().find(".tishishufu").text("姓名不能为空！");
				$(".szName").parent().find(".tishishufu").css("display","initial");
			}
		}
	})
})
// 检测身份证
function checkSFZ(sfzh) {
	var reg = /^[1-9]{1}[0-9]{14}$|^[1-9]{1}[0-9]{16}([0-9]|[xX])$/;
	if (reg.test(sfzh)) {
		$(".szSfz").parent().find(".tishishufu").css("display","none");
		var sfNum = sfzh;
// if(sfNum.substring(10, 12).substring(0,1)==0){
// var moth = sfNum.substring(10, 12).substring(1,2);
// }else{
// var moth = sfNum.substring(10, 12);
// }
// if(sfNum.substring(12, 14).substring(0,1)==0){
// var day = sfNum.substring(12, 14).substring(1,2);
// }else{
// var day = sfNum.substring(12, 14);
// }
		var birthday= sfNum.substring(6, 10) + "-" + sfNum.substring(10, 12) + "-" + sfNum.substring(12, 14); 
		$(".szBri").val(birthday);
		// $(".sr").change();
		return true;
	} else {
		$(".szSfz").parent().find(".tishishufu").text("请输入正确的身份证！");
		$(".szSfz").parent().find(".tishishufu").css("display","initial");
	}
}
